﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using KeMei.Common;

public partial class Manager_lm_default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserInfo"] == null)
        {
            Response.Redirect(ConfigHelper.SystemUrl + "Manager/login.aspx", true);

        }
        if (!IsPostBack)
        {
            BindList();

            btnNew.OnClientClick = Window1.GetShowReference("Edit.aspx", "新增栏目");
        }
    }

    /// <summary>
    /// 绑定列表
    /// </summary>
    private void BindList()
    {

        List<KeMei.Model.Syslm> list = null;
        KeMei.BLL.Syslm bll = new KeMei.BLL.Syslm();
        StringBuilder sql = new StringBuilder();

        try
        {
            sql.Append(" parentID<>0");
            if (!string.IsNullOrEmpty(txtkeyword.Text.Trim()))
            { 
                sql.Append(" and TName like '%"+KeMei.Common.PageValidate.InputText(txtkeyword.Text.Trim(),20)+"%'");
            }

           
            list = bll.GetModelList(sql.ToString());
            Grid1.DataSource = list;
            Grid1.DataBind();
        }
        catch (Exception ex)
        {

            ExtAspNet.Alert.Show(ex.Message);
            
        }
    }

    /// <summary>
    /// 根据ID取得栏目名称
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    protected string GetlmNameById(int ID)
    {
        string result = string.Empty;
        KeMei.BLL.Syslm bll = new KeMei.BLL.Syslm();
        KeMei.Model.Syslm model = null;
        try
        {
            model = bll.GetModel(ID);
            if (model != null)
            {
                result = model.TName;
            }
        }
        catch
        { 
            
        }
        finally
        { 
            
        }

        return result;
    }

    protected void Grid1_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
    {
        int id = Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]);

        if (e.CommandName == "Delete")
        {
            KeMei.BLL.Syslm bll = new KeMei.BLL.Syslm();
            try
            {
                bll.Delete(id);
                BindList();
            }
            catch (Exception ex)
            {
                ExtAspNet.Alert.Show("删除失败：" + ex.Message);
            }
        }
    }

    protected void Window1_Close(object sender, EventArgs e)
    {
        BindList();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        this.BindList();
    }
}